/**
 * Copyright (C) BFH www.bfh.ch 2011
 * Code written by: Patrick Dobler, Marc Folly
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ch.bfh.ti.kybernetik.gui.slick;

import javax.vecmath.Point2d;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Circle;

/**
 * Helper Class to provide some Slick GUI Drawing Utilities
 * 
 */
public final class SlickRenderUtils {

	public static void drawLine(Point2d p1, Point2d p2, Graphics g) {
		g.drawLine((float) p1.getX(), (float) p1.getY(), (float) p2.getX(), (float) p2.getY());
	}

	public static void drawArcBetweenPoints(Graphics g, Point2d centerPoint, Point2d point1, Point2d point2) {
		double radius = Math.sqrt((point2.getX() - centerPoint.getX()) * (point2.getX() - centerPoint.getX())
				+ (point2.getY() - centerPoint.getY()) * (point2.getY() - centerPoint.getY()));

		double x = (double) centerPoint.getX() - radius;
		double y = (double) centerPoint.getY() - radius;

		double width = 2 * radius;
		double height = 2 * radius;

		double startAngle = (double) (180 / Math.PI * Math.atan2(point2.getY() - centerPoint.getY(), point2.getX() - centerPoint.getX()));
		double endAngle = (double) (180 / Math.PI * Math.atan2(point1.getY() - centerPoint.getY(), point1.getX() - centerPoint.getX()));

		g.drawArc((float) x, (float) y, (float) width, (float) height, 100, (float) startAngle, (float) endAngle);
	}

	public static void drawCircle(Graphics g, double centreX, double centreY, double radius) {
		g.drawOval((float) (centreX - radius), (float) (centreY - radius), (float) radius * 2, (float) radius * 2, 100);
	}

	public static Circle getCircle(double centreX, double centreY, double radius) {
		Circle c = new Circle((float) centreX, (float) centreY, (float) radius);
		return c;
	}

	public static void fillCircle(Graphics g, double centreX, double centreY, double radius) {
		g.fillOval((float) (centreX - radius), (float) (centreY - radius), (float) radius * 2, (float) radius * 2, 100);

	}

	public static Color getAlphaColor(Color c, float alphaValue) {
		return new Color(c.getRed(), c.getGreen(), c.getBlue(), alphaValue);
	}

	public static Color convertToSlickColor(java.awt.Color c) {
		Color roboterColer = new Color(c.getRed(), c.getGreen(), c.getBlue());
		return roboterColer;
	}

}
